import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.log4j.Logger;
import org.apache.log4j.varia.StringMatchFilter;

import Temp.Delete.ArrayListIndex;
import Temp.Delete.StringMatchingScore;
import Temp.Delete.TreeMapExample;

import com.mine.crawler.config.DMOZ_XMLProcessor;
import com.mine.crawler.config.InitializeCrawlerApplication;
import com.mine.crawler.config.DOMZFileURLGenerator;
import com.mine.crawler.util.MySqlDataBase;

/*
 * Just a test to see this
 * another one 
 */ 

public class BaseClass
{
	static URL yahoo;
	static BufferedReader in;
	static String inputLine;
	static String[] linkArr = new String[100]; 
	static int LINKS_LIST_SIZE = 100;
	static int toTest;
	
	private static Logger log = Logger.getLogger(BaseClass.class);
	
	public static void main(String[] args)
	{
		//start();
		//ADDing following temporarily
		//TreeMapExample tme = new TreeMapExample();
		//TreeMapExample.main();
		//ArrayListIndex.maine();
		//System.out.println("Score ="+StringMatchingScore.score("Top/World/Bangla","Top"));
		InitializeCrawlerApplication.Initialize();
		DOMZFileURLGenerator.URLFileReader();
		DMOZ_XMLProcessor.XMLProcessing();
		MySqlDataBase.test();
	}
	
	public static void start()
	{
		Map<Integer, String> linkMapPartial = new HashMap<Integer, String>(Constants.LINKS_LIST_SIZE_GLOBAL);
		Map<Integer, String> linkMap = new HashMap<Integer, String>(LINKS_LIST_SIZE);
		
		InitializeCrawlerApplication.Initialize();
		
		try
		{
			yahoo = new URL("http://www.yahoo.com");
			in = new BufferedReader(new InputStreamReader(yahoo.openStream()));
			
			while( (inputLine = in.readLine()) != null )
			{
				System.out.println(inputLine);
				linkMapPartial = myLinkIdentifier.extractURL(inputLine, yahoo.toString());
				linkMap.putAll(linkMapPartial);
				System.out.println();
			}
			in.close();
		}
		
		catch(MalformedURLException e)
		{
			e.printStackTrace();
		}
		
		catch(IOException e)
		{
			e.printStackTrace();
		}
		
		System.out.println("Size of map is "+linkMap.size());
		
		//System.out.println("Map contents are "+linkMap);
	    /*Collection<String> c = linkMap.values();
	    Iterator<String> itr = c.iterator();
	    while (itr.hasNext()) 
	    {
	      System.out.println(itr.next());
	    } */
		Set<Integer> keys = linkMap.keySet();
	    for (Iterator i = keys.iterator(); i.hasNext();) 
	    {
	      Integer key = (Integer) i.next();
	      String value = (String) linkMap.get(key);
	      //System.out.println(key + " = " + value);
	      System.out.println(value);
	    }
	    InitializeCrawlerApplication.PrintPropertiesList();
	}
	
	static void parseLine(String str)
	{
		String[] strArr = new String[10];
		/**
		 * <a .. href
		 * <img .. src= 
		 * <form .. action
		 * <input .. src=
		 * <td .. background
		 * Look for anchor OR http:// OR /xyz
		 * for last case you need to add the base URL
		**/
		//Pattern pattern = Pattern.compile(c"http:.+?(\"|\\s)"); //http followed by "
		//Pattern pattern = Pattern.compile("href(\\s*?)=(\\s*?).+?(\")"); //href followed by "
		Pattern pattern = Pattern.compile("(href|src|)(\\s*?)=(\\s*?).+?(\")"); //src followed by "
		Matcher matcher = pattern.matcher(str); // String 
		
        boolean found = false;
        while (matcher.find()) 
        {
            System.out.printf("I found the text |%s| starting at " +
               "index %d and ending at index %d.%n",
                matcher.group(), matcher.start(), matcher.end());
            found = true;
        }
        
        if(!found)
        {
            System.out.println("No match found.");
        }
	}

}
